package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.dto.ArticleStreamMessage;
import com.heima.article.service.IApArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author Mr_Su
 * @version v1.0
 * @date 2022/7/9 17:01
 * @desciption
 */
@Component
public class HotArticleResultListener {

    @Autowired
    private IApArticleService apArticleService;

    @KafkaListener(topics = "hot_article_result_topic")
    public void updateHotArticle(ConsumerRecord<String,String> record){
        String value = record.value(); // {articleId:"1456088799662469121",view:1 , like:1, comment:1 , collect:2 }
        ArticleStreamMessage articleStreamMessage = JSON.parseObject(value, ArticleStreamMessage.class);
        apArticleService.updateHotArticle(articleStreamMessage);
    }
}
